﻿/*	sIFR 2.0.2
	Copyright 2004 - 2006 Mike Davidson, Shaun Inman, Tomas Jogin and Mark Wubben

	This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
*/

/* ** BEGIN SECURITY CHECK ** */
// Security
currentDomain = _root._url.split("/");
currentDomain = currentDomain[2];
function domainMatch() {
	for (i=0; i < allowedDomains.length; i++) {
		if (allowedDomains[i] == "*" || currentDomain == allowedDomains[i]) {
			return true;
			break;
		}
	}
}
islocal = (_root._url.indexOf("http://") == -1 || _root._url.indexOf("https://") == -1) ? true : false;

/* ** END SECURITY CHECK ** */

function launchURL (index) {
	launchURL_anchor = eval("sifr_url_"+index);
	launchURL_target = eval("sifr_url_"+index+"_target");
	getURL(launchURL_anchor,launchURL_target);
}

function buildText () {
	// Sets stage parameters
	Stage.scaleMode="noscale";
	Stage.align = "TL";
	Stage.showMenu = false;

	allowlocal = true;

	textFormat = holder.txtF.getNewTextFormat();

	// Properties which must be defined within flash:
	// Bold
	// Italic
	
	textcolor = holder.txtF.textColor;
	if (text_color != undefined) {
		if (text_color.indexOf("#") > -1) {
			text_color = text_color.substring(1,7);
		}
		textcolor = "0x" + text_color;
	}

	texthovercolor = holder.txtF.textColor;
	if (hovercolor != undefined) {
		if (hovercolor.indexOf("#") > -1) {
			hovercolor = hovercolor.substring(1,7);
		}
		texthovercolor = "0x" + hovercolor;
	}
	
	size = textFormat.size;
	if ( Number(font_size) > 0 ) {
		size = Number(font_size);
	}

	lineHeight = size + textFormat.leading;
	if ( !isNaN(Number(line_height)) && Number(line_height) > 0 ) {
		lineHeight = Number(line_height);
	}

	leading = 0;
	if ( txt.toLowerCase().indexOf("<br") > -1 ) {
		leading = lineHeight - size;
	}
	
	align = textFormat.align;
	if ( text_align == "left" || text_align == "right" || text_align == "center" || text_align == "justify" ) {
		align = text_align;
	}
	
	w = holder.txtF._width;
	if ( Number(text_width) ) {
		w = text_width;
	}
	
	h = holder.txtF._height;
	if ( Number(text_height) ) {
		h = text_height;
	}
	
	underline = textFormat.underline;
	if ( text_decoration == "underline" ) {
		underline = true;
	}
	
	letterSpacing = textFormat.letterSpacing;
	if ( Number(letter_spacing) ) {
		letterSpacing = Number(letter_spacing);
	}
	
	bold = holder.txtF.htmlText.indexOf("<B>") > -1;
	if ( text_weight == "bold" || (!isNaN(Number(text_weight)) && Number(text_weight) >= 200) ) {
		bold = true;
	}
	
	italic = holder.txtF.htmlText.indexOf("<I>") > -1;
	if ( text_style == "italic" ) {
		italic = true;
	}
	
	yOffset = 0;
	if ( !isNaN(Number(y_offset)) ) yOffset = Number(y_offset);
	
	// Derived settings
	holder.txtF.htmlText = txt;
	holder.txtF._width = w;
	holder.txtF._height = h;

	var fmt = new TextFormat();
	fmt.textWidth = w;
	fmt.textHeight = h;
	fmt.size = size;
	fmt.color = textcolor;
	fmt.leading = leading + yOffset;
	fmt.letterSpacing = letterSpacing;
	fmt.align = align;
	fmt.underline = underline;
	fmt.bold = bold;
	fmt.italic = italic;

	// Fixes
	holder.txtF._x = -2;
	holder.txtF._y = -2 + yOffset;
	holder.txtF.autoSize = "left";
	holder.txtF.condenseWhite = true;
	
	if (url) {
		fmt.url = url;
	}
	
	holder.txtF.setTextFormat(fmt);
	
	if ( url ) {
		if ( display == "block" ) {
			holder.link._x = -2;
			holder.link._y = -2;
			holder.link._width = w;
			holder.link._height = h;
			holder.link._alpha = 0;
		}
		if (texthovercolor && texthovercolor != textcolor) {
			var link_color = new Color(holder.txtF);

			holder.onRollOver = function () {
				link_color.setRGB(parseInt(texthovercolor));
			}

			holder.onRollOut = function () {
				link_color.setRGB(textcolor);
			}
		}


		holder.onRelease = function () {
			getURL(url);
		}
	}
	
	holder._alpha = 100;
}

// if all security tests are passed, build the text
if ((allowlocal && islocal) || domainMatch()) {
	buildText();
}
